package com.example.service.impl;

import com.example.service.OrderService;
import org.springframework.stereotype.Service;

/**
 * 订单服务实现类
 */
@Service
public class OrderServiceImpl implements OrderService {
    
    @Override
    public void add(String pname, int number) {
        // 模拟添加商品到购物车
        System.out.println("成功添加 [" + number + "] 个 [" + pname + "] 到购物车");
        
        // 模拟方法执行耗时
        try {
            Thread.sleep(50);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    }
    
    @Override
    public void delete(String pname) {
        // 模拟从购物车删除商品
        System.out.println("成功从购物车中删除 [" + pname + "]");
        
        // 模拟方法执行耗时
        try {
            Thread.sleep(30);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    }
    
    @Override
    public int find(String pname) {
        // 模拟查询购物车中商品数量
        int randomNumber = (int) (Math.random() * 10) + 1; // 1-10之间的随机数
        System.out.println("查询到购物车中有 [" + randomNumber + "] 个 [" + pname + "]");
        
        // 模拟方法执行耗时
        try {
            Thread.sleep(20);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
        
        return randomNumber;
    }
}
